var app = getApp();
Component({
  properties: {
    attribute: {
      type: Object,
      value:{}
    },
    attrList:{
      type: Object,
      value:[],
    },
    productAttr:{
      type: Object,
      value: [],
    },
    productSelect:{
      type: Object,
      value: {
        pic: '',
        name: '',
        price: 0,

        stock:0,
      }
    },
  },
  data: {
    attrValue:[],
    attrIndex:0,
  },
  attached: function () {
  },
  methods: {
    close: function () {
      this.triggerEvent('myevent', {'window': false});
    },
    CartNumDes:function(){
      this.triggerEvent('ChangeCartNum', false);
    },
    CartNumInt:function(){
      this.triggerEvent('ChangeCartNum', true);
    },
    tapAttr:function(e){
      //父级index
      var indexw = e.currentTarget.dataset.indexw;
      //子集index
      var indexn = e.currentTarget.dataset.indexn;

      //每次点击获得的属性
      var attr = this.data.productAttr[indexw].pics[indexn];
      //设置当前点击属性
      this.data.productAttr[indexw].checked = attr;
      this.setData({
        productAttr: this.data.productAttr,
      });
      var value = this.getCheckedValue().join(',');
      if (value){
        this.triggerEvent('ChangeAttr',value);
      }

    },
    getCheckedValue: function () {
      let productAttr = this.data.productAttr;
      let value = [];
      for (let i = 0; i < productAttr.length; i++) {
        value.push(productAttr[i].checked);
      }
      return value;
    },
    ResetAttr:function(){
      for (var k in this.data.productAttr) this.data.productAttr[k].checked='';
      this.setData({ productAttr: this.data.productAttr});
    },
  }
})
